package com.jgp.glmeeting.service.impl;

import com.jgp.glmeeting.model.Arrangement;
import com.jgp.glmeeting.repository.ArrangementRepository;
import com.jgp.glmeeting.service.ArrangementService;
import com.jgp.sys.common.query.Operator;
import com.jgp.sys.common.query.OrderList;
import com.jgp.sys.common.query.QueryFilterList;
import com.jgp.sys.ui.Pager;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArrangementServiceImpl implements ArrangementService {

@Autowired
private ArrangementRepository arrangementRepository;
    @Override
    public void addArrangement(Arrangement a) {
arrangementRepository.createOrUpdate(a);
    }

    @Override
    public List<Arrangement> queryArrangement(Arrangement a, Pager pager) {
        OrderList orders = new OrderList();
        orders.addOrder("createDatetime","desc");
        String mobilePhone=a.getMobilePhone();
        QueryFilterList queryFilterList=new QueryFilterList();
        if(StringUtils.isNotBlank(mobilePhone)){
            queryFilterList.addFilter("mobilePhone","eq",mobilePhone);
        }

        return arrangementRepository.read(queryFilterList,orders,pager);
    }

    @Override
    public Arrangement queryID(String id) {
        return arrangementRepository.read(id);
    }

    @Override
    public Arrangement queryMobilePhone(String mobilePhone) {
       QueryFilterList queryFilterList=new QueryFilterList();
        queryFilterList.addFilter("mobilePhone","eq",mobilePhone);
       List<Arrangement>lists=arrangementRepository.read(queryFilterList);
        if(lists.size()>0){
            return lists.get(0);
        }
        else{
            return null;
        }
    }

    @Override
    public void removeArrangement(String id) {
arrangementRepository.delete(id);
    }


    @Override
    public List<Arrangement> queryListByParticipantsId(String participantsId) {
        List<Arrangement> list = arrangementRepository.read(new QueryFilterList().addFilter("participantsId", Operator.eq, participantsId));
        return list;
    }
}
